package com.mca.framework.optional;

import com.mca.framework.lambda.Student;

import java.util.Optional;

/**
 * Option是用来判断是否有值，可以防止空指针异常
 */

public class OptionalPresentDemo {

    public  static  void   getStudentName(Student student){
        Optional<Student> optional = Optional.ofNullable(student);
        if(optional.isPresent()){
            //student不为空
            Student student1 = optional.get();
            System.out.println(student1);
        }else {
            System.out.println("student为null");
        }
        optional.ifPresent(s-> System.out.println(s));
    }

    public static void main(String[] args) {
//        Student student=new Student(1,"2323","M");
        Student student=null;
        getStudentName(student);
    }
}
